<template>
  <div class="single-cell">
    <div class='title'>
      {{index}}.{{title}}
    </div>
    <div class='content'>
      <mt-radio v-model="current" :options="optionList"></mt-radio>
      <mt-field placeholder="请输入内容" v-model="other" class="input" v-if="hasOther"></mt-field>
    </div>
  </div>
</template>

<script>
import { Radio, Field } from 'mint-ui';
import getOptionList from '../helpers/getOptionList'
import getNextMap from '../helpers/getNextMap'

export default {
  name: 'SingleSelect',
  components: {
    'mt-radio': Radio,
    'mt-field': Field
  },
  props: {
    index: Number,
    title: String,
    options: String,
    value: String
  },
  data() {
    return {
      current: '',
      other: '',
      hasOther: false
    }
  },
  computed: {
    optionList: function() {
      const {list, hasOther} = getOptionList(this.options);
      this.hasOther = hasOther
      return list
    },
    nextMap() {
      return getNextMap(this.options)
    }
  },
  watch: {
    current: function(val) {
      if (val == '其他') {
        this.$emit('input', this.other, this.nextMap['==!>'])
      }
      else {
        this.$emit('input', val, this.nextMap[val])
      }
    },
    other: function(val) {
      if (this.current == '其他') {
        this.$emit('input', val, this.nextMap['==!>'])
      }
    }
  }
}
</script>

<style lang="scss">
.mint-radio-input {
  vertical-align: top
}
.mint-radio-label {
  vertical-align: bottom
}
.single-cell {
  padding: 50px 40px 0;
}
.single-cell > .title {
  font-size: 34px
}
.single-cell > .content {
  margin-top: 20px;
  position: relative;

  .mint-radiolist {
    .mint-cell-title {
      padding: 10px 0;
    }
  }

  .mint-field {
    input[type="text"] {
      background-color: #f6f6f6;
      border: none;
      border-radius: 6px;
      height: 60px;
      padding:  0 20px;
      font-size: 26px;
      width: calc(100% - 90px);
      margin-left: 50px;
    }
  }
}

</style>